<template>
  <div class="product-list">
    <van-skeleton title :loading="loading" :row="20">
      <van-nav-bar title="详情" left-text="返回" right-text="分享" left-arrow :fixed="true" :placeholder="true"
        @click-left="$router.back(-1)" @click-right="Share">
        <!-- <template #right class="share-title">
          <van-icon name="share-o" size="18" @click="showShare = true" />
          
        </template> -->
      </van-nav-bar>
      <!-- <van-swipe class="my-swipe" :autoplay="5000" lazy-render>
        <van-swipe-item v-for="image in item.F_pic_url" :key="image">
          <img :src="image" />
        </van-swipe-item>
      </van-swipe> -->
      <div class="product-img">
        <img :src="'http://higuang365.com/' + item.F_pic_url" />
      </div>
      <div class="information">
        <div class="group-warp">
          <div class="module-wrap" id="J_mod3">
            <div class="module-price">
              <div class="real-price">
                <span class="ui-yen"><i class="price-symbol">¥</i><span class="price">{{
                  isPromotion ? item.F_FxPrice : item.F_BdPrice
                }}</span></span>
                <span class="icon-text">{{
                  isPromotion ? "限时促销" : "品牌钜惠"
                }}</span>
              </div>
              <div class="item-price" v-if="item.F_Price != item.F_BdPrice">
                <label>价格:</label>
                <del>¥{{ item.F_Price }}</del>
              </div>
            </div>
          </div>
          <div class="module-wrap" id="J_mod4">
            <div class="module-from"></div>
          </div>
          <div class="module-wrap" id="J_mod5">
            <div class="module-title">
              <div class="share-warp">
                <div class="mui-flex">
                  <div class="main cell">
                    {{ item.F_Name }}
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="module-wrap" id="J_mod6">
            <div class="module-adds">
              <!-- <span class="postage">快递: 免运费</span> -->

              <!-- <span class="sales">月销量 {{item.F_yuliu3*8}}件</span> -->

              <div class="delivery" v-if="item.F_yuliu2">
                <img :src="'http://higuang365.com/' + item.F_yuliu2" />
                <div>{{ item.F_BrandCountrie }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="gap"></div>
      <!-- <van-sticky :offset-top="46"> -->
      <div class="mod_tab">
        <div class="J_ping item" @click="modtab = 'details'" :class="{ cur: modtab === 'details' }">
          商品介绍
        </div>
        <!-- <div
            class="J_ping item"
            @click="modtab = 'Spec'"
            :class="{ cur: modtab === 'Spec' }"
          >
            规格参数
          </div> -->
        <!-- <div
            class="J_ping item"
            @click="modtab = 'Aftersales'"
            :class="{ cur: modtab === 'Aftersales' }"
          >
            售后保障
          </div> -->
      </div>
      <!-- </van-sticky> -->
      <div class="details" v-html="item.F_yuliu4"></div>
      <div class="tips">
        划线价格：指商品的专柜价、吊牌价、正品零售价、厂商指导价或该商品的曾经展示过的销售价等，并非原价，仅供参考。<br />
        未划线价格：指商品的实时标价，不因表述的差异改变性质。具体成交价格根据商品参加活动，或使用优惠券、积分等发生变化，最终以订单结算页价格为准。
      </div>
      <!-- <img v-for="image in banner" :key="image" :src="image"/> -->
      <!-- <div class="Spec" v-if="modtab === 'Spec'">
        <div><span>品牌：</span>{{ item.brandName }}</div>
        <div><span>重量：</span>{{ item.weight }}</div>
        <div>
          <span>款式：</span
          ><span v-for="Seq in item.salePropSeq" :key="Seq">{{ Seq[0] }}</span>
        </div>
      </div> -->

      <van-action-bar>
        <van-action-bar-icon icon="chat-o" text="客服" color="#ee0a24" @click="customer" />
        <van-action-bar-icon icon="cart-o" text="购物车" @click="toCart" :badge="$store.state.cartNum" :show-zero="false" />
        <!-- <van-action-bar-icon icon="cart-o" text="购物车" to="../cart" /> -->
        <!-- <van-action-bar-icon
          :icon="star ? 'star' : 'star-o'"
          :text="star ? '已收藏' : '收藏'"
          color="#ff5000"
          @click="star = !star"
        /> -->
        <!-- <van-action-bar-button
          type="warning"
          text="加入购物车"
          @click="joincart"
        /> -->
        <!-- 'http://www.higuang365.com/index.php/wap/passport-signup.html?parents_id=' + -->
        <!-- <div
          style="flex: 1; margin: 2rem"
        > -->
        <van-action-bar-button type="warning" text="加入购物车" @click="
          addBuys($route.query.parents_id, item.F_yuliu3, item.F_ProductId)
          " />

        <van-action-bar-button type="danger" v-if="item.F_Number > 0" text="立即购买" @click="showGoBuys = true" />
        <van-action-bar-button type="danger" v-else text="已售完" />
        <!-- </div> -->

        <!--  -->
      </van-action-bar>
    </van-skeleton>

    <van-overlay :show="showShare" @click="showShare = false" z-index="100">
      <div class="wrapper" @click.stop>
        <van-icon name="share-o" size="100" @click="showShare = true" />
        <div class="sharetips">分享给你的朋友</div>
        <!-- <img class="block" src="//bpic.588ku.com/element_origin_min_pic/19/04/23/a115a1dee787538a628d0220c42bfc57.jpg"/> -->
      </div>
    </van-overlay>
    <!-- goBuys($route.query.parents_id, item.F_yuliu3, item.F_ProductId) -->
    <van-popup v-model:show="showBottom" closeable position="bottom" :style="{ height: '20%' }">
      <div class="WxPopupForm">
        <div class="wxpopup" @click="ShowFriend"><img
            src="http://www.higuang365.com/public/images/common/activity/12_pro.jpg" alt="">
          <div>微信朋友</div>
        </div>
        <div class="wxpopup" @click="showMoments"><img
            src="http://www.higuang365.com/public/images/common/activity/21_pro.jpeg" alt="">
          <div>微信朋友圈</div>
        </div>
      </div>
    </van-popup>

    <van-popup v-model:show="showGoBuys" round position="bottom" closeable>
      <!-- <van-action-sheet v-model:show="showGoBuys" title=" " cancel-text="确定"
      @cancel="goBuys($route.query.parents_id, item.F_yuliu3, item.F_ProductId, true, buysNum)"> -->
      <div class="pro-context">
        <div class="pro-info">
          <img class="pro-img" :src="'http://higuang365.com/' + item.F_pic_url" />
          <div class="real-price">
            <span class="ui-yen"><i class="price-symbol">¥</i><span class="price">{{
              isPromotion ? item.F_FxPrice : item.F_BdPrice
            }}</span></span>
          </div>
        </div>
        <div class="pro-number">
          <span>数量</span>
          <van-stepper v-model="buysNum" min="1" :max="item.F_yuliu8 && isPromotion ? item.F_yuliu8 : item.F_Number"
            integer disable-input />
        </div>
        <div style="margin: -2rem 0 1rem;color: red;" v-if="item.F_yuliu8 && isPromotion">
          每个账户首单享受活动价，限购{{ item.F_yuliu8 }}套,售完即止
        </div>
      </div>
      <div class="pro-buys" color="linear-gradient(to right, #ff6034, #ee0a24)" @click="
        goBuys(
          $route.query.parents_id,
          item.F_yuliu3,
          item.F_ProductId,
          true,
          buysNum
        )
        ">
        确定
      </div>
    </van-popup>
  </div>
</template>

<script>
import { reactive, toRefs } from "vue";
import { useRoute, useRouter } from "vue-router";
import { Details } from "@/api/home";
import { getCookie, addBuys, goBuys, wxapi } from "@/lib/ecapi";

export default {
  name: "product-list",
  setup() {
    const data = reactive({
      banner: [],
      price: 0,
      name: "",
      item: {},
      modtab: "details",
      showShare: false,
      showBottom: false,
      loading: true,
      star: true,
      sharewx: [],
      isPromotion: false,
      showGoBuys: false,
      buysNum: 1,
    });
    const route = useRoute();
    const router = useRouter();
    const { id } = route.query;
    // hbuilder包分享到微信朋友
    const ShowFriend = () => {

      Share('WXSceneSession')
      // data.showBottom = false
    }
    // hbuilder包分享到微信朋友圈
    const showMoments = () => {

      Share('WXSceneTimeline')
      // data.showBottom = false

    }
    const customer = () => {
      window.location.href =
        "http://qfck70.kuaishang.cn/bs/im.htm?cas=3514___580971&fi=4006";
    };
    const Share = (showtype) => {
      // console.log(type, '1111');
      if (!getCookie("S[MEMBER]")) {
        window.location.href = "http://www.higuang365.com/wap/passport.html";
        return;
      }

      let msg = {
        title: "嗨逛全球", //标题
        content: data.item.F_Name, //内容
        purl: "http://www.higuang365.com/" + data.item.F_pic_url, //可以是本地图片
        surl:
          "http://www.higuang365.com/wap/#/product?id=" +
          data.item.F_ProductId +
          "&parents_id=" +
          data.item.F_yuliu1, //分享的链接
      };
      if (navigator.userAgent.indexOf("haiguang_mobile") > -1) {
        window.location.href = `higuang|shareGood|${msg.title}|${msg.content}|${msg.purl}|${msg.surl}`;
      }
      else if (navigator.userAgent.indexOf("Html5Plus") > -1) {
        if (data.showBottom == false) {
          data.showBottom = true
        }
        let inviteShare = function (types) {
          let shareObj = null;
          plus.share.getServices(
            //获取分享服务成功
            function (services) {
              for (const i in services) {
                //判断微信分享服务
                if (services[i].id == "weixin") {
                  shareObj = services[i];
                }
              }
              if (shareObj == null) {
                plus.nativeUI.toast("获取分享服务失败");
                return;
              }
              //这里我选择使用同步来让他先获取分享的超链接

              //分享核心代码
              shareObj.send(
                //朋友圈{content:"hi....",thumbs:['_www/shareLogo.png'], href:'http://hcoder.net',title:'test'},
                //微信好友
                {
                  //分享的内容
                  content: msg.content,
                  //商品的缩略图
                  thumbs: [msg.purl],
                  //链接
                  href: msg.surl,
                  //标题
                  title: "嗨逛全球",
                  //分享到微信聊天   'WXSceneSession'分享给好友，'WXSceneTimeline'分享到朋友圈
                  extra: { scene: types }
                },
                function () {
                  // alert('分享成功')

                },
                function (e) {
                  alert("分享失败：" + e.message);
                }
              );
            },
            //获取分享服务失败
            function (e) {
              alert(e.message);
            }
          );
        }
        if (showtype == "WXSceneTimeline") {
          inviteShare('WXSceneTimeline')
        } else if (showtype == "WXSceneSession") {
          inviteShare('WXSceneSession')
        } else {
          return
        }
      } else {
        data.showShare = true;
      }
    };
    const toCart = () => {
      window.location.href = "http://www.higuang365.com/wap/cart.html";
    };
    const load = async () => {
      const res = await Details({
        goodsid: id,
        member_id: getCookie("S[MEMBER]"),
        Strlv: getCookie("MLV"),
      });
      data.loading = false;
      data.item = res[1][0];
      // router.replace({ query:{ id: id, parents_id: 111 }});
      if (getCookie("S[MEMBER]")) {
        router.replace({ query: { id: id, parents_id: data.item.F_yuliu1 } });
      }
      wxapi(
        "嗨逛全球",
        data.item.F_Name,
        "http://www.higuang365.com/wap/#/product?id=" +
        data.item.F_ProductId +
        "&parents_id=" +
        data.item.F_yuliu1,
        "http://www.higuang365.com/" + data.item.F_pic_url
      );

      data.isPromotion =
        new Date().getTime() <= new Date(data.item.F_yuliu10).getTime() &&
        new Date().getTime() >= new Date(data.item.F_yuliu9).getTime() &&
        data.item.F_yuliu8;
    };
    load();
    return { ...toRefs(data), customer, addBuys, Share, goBuys, toCart, ShowFriend, showMoments };
  },
};
</script>
<style lang="scss" scoped>
@import "@/common/style/mixin";

.product-list {
  font-size: 1.5rem;
}

.my-swipe {
  height: 100vw;

  img {
    width: 100vw;
    height: 100vw;
  }
}

.product-img {
  height: 100vw;
}

.WxPopupForm {
  display: flex;

  .wxpopup {
    width: 8rem;
    height: 8rem;
    margin: 20px;

    img {
      width: 80%;
      height: 80%;
      border-radius: 50px;
    }
  }
}

.information {
  text-align: left;
}

.gap {
  width: 100%;
  height: 1rem;
  background: #f5f5f5;
}

.module-price {
  background-color: #fff;
  padding: 0 10px;
}

.real-price {
  color: #ff0036;
  height: 3.6rem;
  line-height: 3.6rem;

  .ui-yen .price-symbol {
    font-family: arial;
    font-style: normal;
    font-size: 1.8rem;
    position: relative;
    top: 2px;
  }

  .ui-yen .price {
    font-size: 2.4rem;
    position: relative;
    top: 2px;
    margin-right: 0.5rem;
  }

  .icon-text {
    background-color: #fb6878;
    color: #fff;
    font-size: 1.2rem;
    padding: 1px 2px;
  }
}

.item-price {
  font-size: 1.2rem;
  height: 2rem;
  line-height: 2rem;
  color: #888;
  display: inline-block;
  margin-right: 1rem;
  font-family: "\5fae\8f6f\96c5\9ed1";
}

.module-title .share-warp {
  padding: 3px 10px 0 !important;
  background-color: #fff;
}

.mui-flex {
  display: flex;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.module-title .main {
  font-size: 1.4rem;
  color: #051b28;
  line-height: 2rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  max-height: 6.3rem;
  -webkit-box-orient: vertical;
  -webkit-box-pack: center;
  overflow: hidden;
  word-break: break-all;
}

.mui-flex>.cell {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
  width: 0;
  -webkit-flex-basis: 0;
  -ms-flex-preferred-size: 0;
  flex-basis: 0;
  max-width: 100%;
  display: block;
  padding: 0 !important;
  position: relative;
}

.module-adds {
  display: -webkit-box;
  display: flex;
  background-color: #fff;
  padding: 0.5rem 1rem;
  font-size: 1.2rem;
  color: #999;
  justify-content: space-between;

  .delivery {
    display: flex;

    img {
      width: 2rem;
    }
  }
}

.Spec {
  div {
    border: 1px solid;
  }
}

.details {
  min-height: 600px;
  margin-bottom: 2rem;
}

.mod_tab {
  display: flex;
  background: #fff;

  .item {
    flex: 1;
    height: 3.6rem;
    line-height: 2.2rem;
    padding-top: 1.5rem;
  }

  .item.cur {
    position: relative;
    font-weight: 700;
    color: #262626;
  }

  .item.cur:after {
    position: absolute;
    left: 50%;
    bottom: 6px;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
    content: "";
    display: block;
    width: 2.6rem;
    height: 3px;
    background-image: -webkit-gradient(linear,
        left top,
        right top,
        from(#f5503a),
        to(#fad1cb));
    background-image: -webkit-linear-gradient(left, #f5503a, #fad1cb);
    background-image: linear-gradient(90deg, #f5503a, #fad1cb);
  }
}

.tips {
  font-size: 1.2rem;
  margin-bottom: 5rem;
}

.wrapper {
  i {
    color: #fff;
    transform: translate3d(12rem, 20px, 0px) rotate3d(30, -24, 0, 180deg);
  }

  .sharetips {
    color: #fff;
    font-size: 2rem;
  }
}

.pro-context {
  &>div {
    margin: 4rem;
  }

  .pro-info {
    display: flex;

    .pro-img {
      width: 10rem;
      height: 10rem;
    }

    .real-price {
      margin-left: 4rem;
      margin-top: 5rem;
    }
  }

  .pro-number {
    display: flex;
    justify-content: space-between;
  }
}

.pro-buys {
  background: linear-gradient(to right, #fc8d3e, #ff6636);
  height: 3.5rem;
  line-height: 3.5rem;
  color: #fff;
  border-radius: 3rem;
  margin: 0.5rem 2rem;
}
</style>
